package id.net.iconpln.bb.client.tools;

import id.net.iconpln.bb.client.service.MasterRPCService;
import id.net.iconpln.bb.client.service.MasterRPCServiceAsync;
import id.net.iconpln.bb.client.util.ClientModule;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.core.FastMap;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class GridPemasokPLTU extends Grid{
	private String id_pltu;
	private final MasterRPCServiceAsync serviceMaster = GWT.create(MasterRPCService.class);
	
	public GridPemasokPLTU(String id_pltuParam) {
		super();
		// TODO Auto-generated constructor stub
		id_pltu = id_pltuParam;
	}
	
	

	@Override
	protected void onRender(Element target, int index) {
		// TODO Auto-generated method stub
		super.onRender(target, index);
		store = new ListStore();
		store.setMonitorChanges(true);  
		
		Map mapParam = new FastMap();
		mapParam.put("id_pltu", id_pltu);
		serviceMaster.getMaster("PEMASOK_BY_PLTU", mapParam, new AsyncCallback<List<Map>>() {
			public void onFailure(Throwable caught) {
				GWT.log(caught.getMessage(), null);
			}

			public void onSuccess(List<Map> result) {	
				store.removeAll();
				store.add(ClientModule.setListBaseModelFromListMap(result));
			}
		});
		
		List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  

	    ColumnConfig column = new ColumnConfig();
	    column = new ColumnConfig("id_pemasok", "ID", 50);  
	    configs.add(column);
	    
	    column = new ColumnConfig("pemasok", "Pemasok", 200);  
	    configs.add(column);
	    
	    column = new ColumnConfig("alamat", "Alamat",250);  
	    configs.add(column);  
	    
	    cm = new ColumnModel(configs);  
	    
		getView().setEmptyText("Data Empty");  
	    setBorders(true); 
	    getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
	}
	

}
